<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="year" required>
    <input type="text" id="month" required>
    <input type="text" id="day" required>
    <button id="dian">查询这是第几天</button>
    <div id="tianshu"></div>
</body>

</html>
<script>
    var year = document.getElementById('year');
    var month = document.getElementById('month');
    var day = document.getElementById('day');
    var dian = document.getElementById('dian');


    dian.onclick = function() {
        var year1 = year.value - 0,
            month1 = month.value - 0,
            day1 = day.value - 0,
            daya;
        var sum = 0;

        var tianshu = document.getElementById('tianshu');

        for (i = 1; i <= month1; i++) {

            if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                daya = 31;
            } else if (i == 2) {
                if (year1 % 4 == 0 && year1 % 100 != 0 || 400 % year1 == 0) {
                    daya = 29;
                } else {
                    daya = 28;
                }
            } else {
                daya = 30;
            };
            sum = sum + daya;
        }
        // console.log(sum);
        // ----------------------------------------------------------------------------------
        if (month1 == 1 || month1 == 3 || month1 == 5 || month1 == 7 || month1 == 8 || month1 == 10 || month1 == 12) {
            daya1 = 31;
        } else if (month1 == 2) {
            if (year1 % 4 == 0 && year1 % 100 != 0 || 400 % year1 == 0) {
                daya1 = 29;
            } else {
                daya1 = 28;
            }

        } else {
            daya1 = 30;
        };
        // console.log(daya);
        // console.log(i, typeof i);

        sum = sum - daya1 + day1;

        tianshu.innerHTML = sum;
    }
</script>